package com.xfgg.design.singleton;

/**
 * 容器式
 *
 * @author xfgg
 */
public class Container {
    private static Container container;

    private Container() {

    }

    public static Container getContainer() {
        if (container == null) {
            container = new Container();
        }
        return container;
    }

    public void doSomething() {
        // do something
    }
    /**
     * 在Spring的配置文件中定义该类的Bean
     * <bean id="mySingleton" class="com.example.MySingleton" scope="singleton"/>
     *在Java代码中获取该Bean
     * ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
     * MySingleton mySingleton = (MySingleton) context.getBean("mySingleton");
     * mySingleton.doSomething();
     */
}
